/*
 * @Author      : 🐝小蜜蜂🐝
 * @Date        : 2022-06-09 07: 18: 40
 * @LastEditTime: 2023-06-29 07:08:58
 * @LastEditors: 🐝小蜜蜂🐝 
 * @Description : 
 * @FilePath: /handheld-terminal-app/lib/pages/splash_page.dart
 * @CopyRight：小蜜蜂🐝  QQ：834537795
 */
import 'package:flutter/material.dart';
import 'package:material_collection_app/pages/home_page.dart';

class SplashPage extends StatefulWidget {
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage>
    with SingleTickerProviderStateMixin {
  AnimationController _animationController;
  Animation _animation;

  void initState() {
    super.initState();
    //创建动画控制器
    _animationController =
        AnimationController(vsync: this, duration: Duration(seconds: 2));
    _animation = Tween(begin: 1.0, end: 1.0).animate(_animationController);
    _animation.addStatusListener((status) {
      // 倒计时结束
      if (status == AnimationStatus.completed) {
        Navigator.of(context).pushAndRemoveUntil(
            MaterialPageRoute(builder: (context) => new HomePage()),
            (route) => route == null);
      }
    });
    _animationController.forward();
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return FadeTransition(
        opacity: _animation,
        child: ConstrainedBox(
            //让他的child充满整个屏幕
            constraints: BoxConstraints.expand(),
            child: Stack(children: <Widget>[
              Container(
                width: double.infinity,
                height: double.infinity,
                color: Colors.white,
                child: Image.asset('assets/splash_bg.png',
                    scale: 1.0, fit: BoxFit.cover),
              )
            ])));
  }
}
